package com.catering.until;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResultData<T> implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private boolean success = true;
	private String code;
	private String msg;
	private T data;
	private Integer count = 0;
	
	public ResultData() {}
 
	public ResultData(String code, String msg, T data ,boolean success) {
		this.success = success;
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
   
	public static ResultData error(String msg) {
		ResultData<Object> result = new ResultData();
		result.setCode(ResultEnum.CODE_FAILURE.getCode());
		result.setMsg(msg);
		result.setData(null);
		result.setSuccess(false);
		return result;
	}
	
	public static ResultData error(String code, String msg) {
		ResultData<Object> result = new ResultData();
		result.setCode(code);
		result.setMsg(msg);
		result.setSuccess(false);
		result.setData(null);
		return result;
	}
	
	public static ResultData<Object> success(Object data,Integer count) {
		ResultData<Object> result = new ResultData<Object>();
		result.setCode(ResultEnum.CODE_SUCCESS.getCode());
		result.setMsg(ResultEnum.CODE_SUCCESS.getMsg());
		result.setData(data);
		result.setSuccess(true);
		result.setCount(count);
		return result;
	}
	
	public static ResultData success(Object data) {
		ResultData<Object> result = new ResultData();
     	result.setData(data);
     	result.setSuccess(true);
     	result.setCode(ResultEnum.CODE_SUCCESS.getCode());
		result.setMsg(ResultEnum.CODE_SUCCESS.getMsg());
     	return result;
	}
	
	public static ResultData success() {
		ResultData<Object> result = new ResultData();
		result.setData(null);
		result.setSuccess(true);
		result.setCode(ResultEnum.CODE_SUCCESS.getCode());
		result.setMsg(ResultEnum.CODE_SUCCESS.getMsg());
		return result;
	}
 
 }
